package com.front.managementfront.company.service.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.front.managementfront.company.entity.Company;
import com.front.managementfront.company.mapper.CompanyMapper;
import com.front.managementfront.company.service.ICompanyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.apache.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yck
 * @since 2021-05-20
 */
@Service
@Transactional
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> implements ICompanyService {


@Autowired
private CompanyMapper companyMapper;

@Override
public IPage<Company> selectPage(Page<Company> page, Company company){
        QueryWrapper<Company> query = Wrappers.query();
        QueryWrapper<Company> entityWrapper = getEntityWrapper(query, company);
        return companyMapper.selectPage(page, entityWrapper);
        }




@Override
public List<Company> selectList(Company company){
        QueryWrapper<Company> query = Wrappers.query();
        QueryWrapper<Company> entityWrapper = getEntityWrapper(query, company);
        return companyMapper.selectList(entityWrapper);
        }

/**
 *  公共查询条件
 * @param entityWrapper
 * @return
 */
public QueryWrapper<Company> getEntityWrapper(QueryWrapper<Company> entityWrapper,Company company){
        //条件拼接
                if(StringUtils.isNotBlank(company.getName())){
                entityWrapper.like(Company.NAME,company.getName());
                }
                if(StringUtils.isNotBlank(company.getUserId())){
                entityWrapper.like(Company.USER_ID,company.getUserId());
                }
        return entityWrapper;
        }
        }
